package com.by.sbdemoby.filter;

import com.by.sbdemoby.model.AjaxResult;
import com.by.sbdemoby.utils.ResponseUtils;

import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @auth wzy
 * @date 2023/12/9 11:34
 */
public class ExceptionHandlerFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        try {
            filterChain.doFilter(servletRequest, servletResponse);
        } catch (Exception e) {
            ResponseUtils.out((HttpServletResponse) servletResponse, AjaxResult.error(e.getMessage()));
        }
    }
}
